********************************************************************************
***                                Preamble                                  ***
********************************************************************************
* Project: Counter-Punishment
* Procedure: Analysis
* version 15
clear all
macro drop _all
********************************************************************************

********************************************************************************
					*** SUMMARY STATISTICS ***
********************************************************************************
use counterpunish.dta, clear
	gen id=_n

reshape long counter counter_prob, i(id) j(punishment)
	drop id session_code player

// COUNTER-PUNISHMENT
bysort treat: sum take counter counter_prob if type==1	


***********
* TABLE 1 *
***********
use counterpunish.dta, clear
	gen id=_n

reshape long counter counter_prob, i(id) j(punishment)
	drop id session_code player
	
gen exp_counter = counter * counter_prob
la var punishment "Punishment"

la var counter "Counter-punishment"
la var counter_prob "Counter-punishment decision"

reg counter punishment i.treat c.punishment#i.treat if type==1, cl(group)
reg counter punishment i.treat c.punishment#i.treat take if type==1, cl(group)		
reg counter_prob punishment i.treat c.punishment#i.treat if type==1, cl(group)
reg counter_prob punishment i.treat c.punishment#i.treat take if type==1, cl(group)
reg counter punishment i.treat c.punishment#i.treat if type==1 & counter>0, cl(group)
reg counter punishment i.treat c.punishment#i.treat take if type==1 & counter>0, cl(group)

*********************
* TABLE A1 - Part 1 *
*********************
reg counter punishment i.treat c.punishment#i.treat take c.take#i.treat open conscient extro agree neuro if type==1, cl(group)		
reg counter_prob punishment i.treat c.punishment#i.treat take c.take#i.treat open conscient extro agree neuro if type==1, cl(group)		
reg counter punishment i.treat c.punishment#i.treat take c.take#i.treat open conscient extro agree neuro if type==1 & counter>0, cl(group)		

*********************
* TABLE A1 - Part 2 *
*********************
use counterpunish.dta, clear	
gen id=_n

reshape long punish punish_prob, i(id) j(taking)
drop id session_code player

gen exp_punish = punish * punish_prob

reg punish taking i.treat if type==2 & punish > 0, cl(group)
reg punish taking i.treat c.taking#i.treat if type==2 & punish > 0, cl(group)
reg punish taking i.treat c.taking#i.treat take c.take#i.treat open conscient extro agree neuro if type==2 & punish > 0, cl(group)	
	
	
	
// additional table appendix
use counterpunish.dta, clear
	gen id=_n

gen punish = .
forvalues i=0(5)10{
	replace punish = 0 if take == `i' & punish`i' == 0
	replace punish = 1 if take == `i' & punish`i' != 0
}

gen counterpunish = .
forvalues i=0(5)10{
	forvalues j = 0(10)100{
	replace counterpunish = 0  if take == `i' & punish`i' == `j' & counter`j' == 0
	replace counterpunish = 1  if take == `i' & punish`i' == `j' & counter`j' != 0
	}
}

bysort treat: tab punish counterpunish

	